home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_10_12
/
1012077a
< prev
next >
Wrap
Text File
|
1992-10-11
|
689b
|
36 lines
/* token3.c: Read comma-delimited fields */
#include <stdio.h>
#include <string.h>
main()
{
char s[81];
while (gets(s))
{
char *p, *sp = s;
int nchars;
do
{
/* Make p point at next comma, or '\0'*/
if ((p = strchr(sp,',')) == NULL)
p = sp + strlen(sp);
nchars = p - sp;
/* Print the field */
if (sp > s)
putchar(',');
printf("\"%.*s\"",nchars,sp);
/* Position at start of next field */
sp = p+1;
} while (*p != '\0');
putchar('\n');
}
return 0;
}